import {request} from "vendor/utils/T";
import {toApi} from "@/service/proxyApi";
import {RequestDataType, RespDataType} from "./apiType";

export * from "./apiType";

const {get, postJSON, del, put} = request;

/**
 * 获取字典分页列表
 */
export const getDictionaryPageList = (params: { page: number, pageSize: number, dictName?: string, dictType?: string }) => {
    return get<RespDataType.DictionaryPageList>(toApi("system/dict/type/list"), params);
}

/**
 * 创建字典
 */
export const createDictionary = (params: RequestDataType.CreateDictionaryItem) => {
    return postJSON(toApi("system/dict/type"), params);
}

/**
 * 获取字典信息
 */
export const getDictionaryInfo = (dictId: number) => {
    return get<RespDataType.DictionaryItem>(toApi("system/dict/type"), {dictId});
}

/**
 * 更新字典信息
 */
export const updateDictionary = (dictId: number, params: Partial<RequestDataType.UpdateDictionaryItem>) => {
    return put(toApi(`system/dict/type?dictId=${dictId}`), params);
}

/**
 * 删除字典信息
 */
export const deleteDictionary = (dictIds: number[]) => {
    return del(toApi(`system/dict/type`), {ids: dictIds});
}

